package com.zxl.web.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * 使用切面定义方法的执行逻辑
 */
@Aspect
@Component
public class TimeAspect {

    @Around("execution(* com.zxl.web.controller.UserController.*(..))")// 定义切入点
    public Object handleControllerMethod(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("time aspect start...");
        Object[] args = joinPoint.getArgs();// 获取切入的方法的所有参数
        for (Object arg : args) {
            System.out.println("方法参数=" + arg);
        }
        long start = System.currentTimeMillis();
        Object proceed = joinPoint.proceed();// 执行切入方法
        long end = System.currentTimeMillis();
        System.out.println("执行方法总耗时：" + (end - start));
        return proceed;
    }
}
